<template>
  <div class="app-container">
    <el-upload
      class="upload-demo"
      drag
      :on-success="onsuccess"
      action="/api/admin/upload/xlsx"
      multiple
    >
      <i class="el-icon-upload"></i>
      <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
      <div class="el-upload__tip" slot="tip">只能导入xlsx</div>
    </el-upload>
<el-card class="box-card">
   <el-table :data="tableData" style="width: 100%" border>
      <el-table-column
        v-for="(v, i) in column"
        :key="v"
        :prop="'xlsx'+i"
        :label="v"
      >
      </el-table-column>
    </el-table>
</el-card>

  </div>
</template>

<script>
export default {
  data() {
    return {
      column: [],
      tableData: [

      ],
    };
  },
  created() {},
  methods: {
    onsuccess(response, file, fileList) {
      this.column = file.response.datas[0];


      file.response.datas.slice(1, -1).forEach((v, i) => {
        console.log(i, v);
        // v = {i+'xlsx':v[]}
        var temp = {}
        for (let index = 0; index < v.length; index++) {
          temp[ "xlsx"+index] = v[index]
        }
        console.log(temp);
        this.tableData.push(temp)
      });
      console.log(this.tableData);
    },
  },
};
</script>
